home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_eroded.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  940 b   |  38 lines

  1. /* Copyrighted Pixar 1989 */
  2. /* From the RenderMan Companion p.353 */
  3. /* Listing 16.17  Surface shader eroding the surface of an object */
  4.  
  5. /*
  6.  * eroded(): Simulate a metallic surface eaten away with acid
  7.  */
  8. surface
  9. k3d_eroded (
  10.     float Ks = 0.4,
  11.           Ka = 0.1,
  12.           Km = 0.3,
  13.           roughness = 0.25)
  14. {
  15.     float size = 4.0,
  16.           magnitude = 0.0,
  17.           i;
  18.     point Nf,
  19.           W = transform ("object", P);
  20.     point x = (1, 0, 0);
  21.     point V = normalize(-I);
  22.     
  23.     for (i = 0; i < 6.0; i += 1.0) {
  24.         /* Calculate a simple fractal 1/f noise function */
  25.         magnitude += 4.0 * abs (.5 - noise (W * size)) / size;
  26.         size *= 2.0;
  27.     }
  28.     
  29.     /* sharpen peaks */
  30.     magnitude = magnitude * magnitude * magnitude * Km;
  31.     
  32.     N = calculatenormal (P - magnitude * normalize(N));
  33.     
  34.     Nf = faceforward (normalize (N), I);
  35.     Oi = smoothstep (0.0001, 0.003, magnitude);
  36.     Ci = Oi * Cs * (Ka * ambient() + Ks * specular (Nf, V, roughness) );
  37. }
  38.